Moving more of our core data structures to QStrings.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 30 Mar 2013 04:53:47 +0000 (04:53 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 30 Mar 2013 04:53:47 +0000 (04:53 +0000)
gpsbabel/cetus.cc
gpsbabel/defs.h
gpsbabel/delbin.cc
gpsbabel/html.cc
gpsbabel/kml.cc
gpsbabel/palmdoc.cc
gpsbabel/text.cc
gpsbabel/util.cc
gpsbabel/waypt.cc

index f8d8e63941ddc6a5658ba773ad1ca3d460b3fb95..bf646f00c8087b6e8f7606a0a456a4470a8eac6b 100644 (file)
@@ -514,7 +514,7 @@ cetus_writewpt(const waypoint* wpt)
     desc_geo = xstrdup("");
   }
 
-  if (wpt->gc_data->desc_short.utfstring) {
+  if (!wpt->gc_data->desc_short.utfstring.isEmpty()) {
     char* stripped_html = strip_html(&wpt->gc_data->desc_short);
     desc_short = xstrdup(wpt->gc_data->diff == 0 ? "\n\n" : "");
     desc_short = xstrappend(desc_short, xstrdup(stripped_html));
@@ -523,7 +523,7 @@ cetus_writewpt(const waypoint* wpt)
     desc_short = xstrdup("");
   }
 
-  if (wpt->gc_data->desc_long.utfstring) {
+  if (!wpt->gc_data->desc_long.utfstring.isEmpty()) {
     char* stripped_html = strip_html(&wpt->gc_data->desc_long);
     desc_long = xstrdup("\n\n");
     desc_long = xstrappend(desc_long, xstrdup(stripped_html));
index 5a27eb0edf49b522c98fefcd1bf0535324ef5779..8a709b20d0acfabaf72c52ffb6d3323f15c068f4 100644 (file)
@@ -263,11 +263,10 @@ typedef enum {
 class utf_string{
  public:
   utf_string() :
-    is_html(false),
-    utfstring(NULL)
+    is_html(false)
   {};
   bool is_html;
-  char* utfstring;
+  QString utfstring;
 };
 
 class geocache_data {
@@ -996,7 +995,7 @@ const char* gs_get_container(geocache_container t);
 char* xml_entitize(const char* str);
 char* html_entitize(const char* str);
 char* strip_html(const utf_string*);
-char* strip_nastyhtml(const char* in);
+char* strip_nastyhtml(const QString& in);
 char* convert_human_date_format(const char* human_datef);      /* "MM,YYYY,DD" -> "%m,%Y,%d" */
 char* convert_human_time_format(const char* human_timef);      /* "HH+mm+ss"   -> "%H+%M+%S" */
 char* pretty_deg_format(double lat, double lon, char fmt, const char* sep, int html);    /* decimal ->  dd.dddd or dd mm.mmm or dd mm ss */
@@ -1027,7 +1026,7 @@ xml_tag* xml_findfirst(xml_tag* root, const char* tagname);
 xml_tag* xml_findnext(xml_tag* root, xml_tag* cur, const char* tagname);
 char* xml_attribute(xml_tag* tag, const char* attrname);
 
-char* rot13(const char* str);
+char* rot13(const QString& str);
 
 /*
  * PalmOS records like fixed-point numbers, which should be rounded
index 51635ae4db6ed59ede3d10a6f26cacc0b6aee0cf..7846c44675b62ab18e887962bc7fb764ce90ead6 100644 (file)
@@ -1246,16 +1246,16 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size
   if (wp->gc_data->hint && !opt_hint_at_end) {
     gbfprintf(fd, "HINT: %s\n", wp->gc_data->hint);
   }
-  if (wp->gc_data->desc_short.utfstring || wp->gc_data->desc_long.utfstring) {
+  if (!wp->gc_data->desc_short.utfstring.isEmpty() || !wp->gc_data->desc_long.utfstring.isEmpty()) {
     gbfputs("DESC: ", fd);
-    if (wp->gc_data->desc_short.utfstring) {
+    if (!wp->gc_data->desc_short.utfstring.isEmpty()) {
       char* s1 = strip_html(&wp->gc_data->desc_short);
       char* s2 = cet_str_utf8_to_any(s1, global_opts.charset);
       gbfprintf(fd, "%s\n", s2);
       xfree(s2);
       xfree(s1);
     }
-    if (wp->gc_data->desc_long.utfstring) {
+    if (!wp->gc_data->desc_long.utfstring.isEmpty()) {
       char* s1 = strip_html(&wp->gc_data->desc_long);
       char* s2 = cet_str_utf8_to_any(s1, global_opts.charset);
       gbfputs(s2, fd);
index 57c154fe7e6fad784538c73784924528fd0438b7..f24c57f951735f8a41a04b34fc3c6a8ee10ec63a 100644 (file)
@@ -134,12 +134,12 @@ html_disp(const waypoint* wpt)
 
 
   gbfprintf(file_out, "<tr><td colspan=\"2\">");
-  if (wpt->gc_data->desc_short.utfstring) {
+  if (!wpt->gc_data->desc_short.utfstring.isEmpty()) {
     char* tmpstr = strip_nastyhtml(wpt->gc_data->desc_short.utfstring);
     gbfprintf(file_out, "<p class=\"gpsbabeldescshort\">%s</p>\n", tmpstr);
     xfree(tmpstr);
   }
-  if (wpt->gc_data->desc_long.utfstring) {
+  if (!wpt->gc_data->desc_long.utfstring.isEmpty()) {
     char* tmpstr = strip_nastyhtml(wpt->gc_data->desc_long.utfstring);
     gbfprintf(file_out, "<p class=\"gpsbabeldesclong\">%s</p>\n", tmpstr);
     xfree(tmpstr);
index be6b21de7a19d0cdfa88b5cdcddbed1bc87c5412..6a1f4c1c778f0322e413bbb7b918adb41aedf2b9 100644 (file)
@@ -1420,7 +1420,7 @@ static void kml_write_data_element(const char* name, const double value)
   AUTOFORMATTING_RESTORE(af);
 }
 
-static void kml_write_cdata_element(const char* name, const char* value)
+static void kml_write_cdata_element(const char* name, const QString& value)
 {
   writer.writeStartElement("Data");
   writer.writeAttribute("name", name);
@@ -1503,8 +1503,8 @@ static void kml_geocache_pr(const waypoint* waypointp)
 
   kml_write_data_element("gc_type", gs_get_cachetype(waypointp->gc_data->type));
   kml_write_data_element("gc_icon", is);
-  kml_write_cdata_element("gc_short_desc", waypointp->gc_data->desc_short.utfstring ? waypointp->gc_data->desc_short.utfstring : "");
-  kml_write_cdata_element("gc_long_desc", waypointp->gc_data->desc_long.utfstring ? waypointp->gc_data->desc_long.utfstring : "");
+  kml_write_cdata_element("gc_short_desc", waypointp->gc_data->desc_short.utfstring);
+  kml_write_cdata_element("gc_long_desc", waypointp->gc_data->desc_long.utfstring);
   logs = kml_geocache_get_logs(waypointp);
   kml_write_cdata_element("gc_logs", logs);
   xfree(logs);
index 4fa0a8f257d9db811e5f8d48b8f7f4dee029e66b..43c820a6f89b7be33d8ff91ad36670942baa23aa 100644 (file)
@@ -454,12 +454,12 @@ palmdoc_disp(const waypoint *wpt)
     docprintf(100, "%s/%s\n", gs_get_cachetype(wpt->gc_data->type),
               gs_get_container(wpt->gc_data->container));
 
-    if (wpt->gc_data->desc_short.utfstring) {
+    if (!wpt->gc_data->desc_short.utfstring.isEmpty()) {
       char *stripped_html = strip_html(&wpt->gc_data->desc_short);
       docprintf(10+strlen(stripped_html), "\n%s\n", stripped_html);
       xfree(stripped_html);
     }
-    if (wpt->gc_data->desc_long.utfstring) {
+    if (!wpt->gc_data->desc_long.utfstring.isEmpty()) {
       char *stripped_html = strip_html(&wpt->gc_data->desc_long);
       docprintf(10+strlen(stripped_html), "\n%s\n", stripped_html);
       xfree(stripped_html);
index 8aed2fce22990aa82e09f38a1d0718cd44f1595c..7a65a66f19bf9dbc6c0801c90c733317d6eeec9c 100644 (file)
@@ -152,12 +152,12 @@ text_disp(const waypoint *wpt)
               gs_get_cachetype(wpt->gc_data->type), gs_get_container(wpt->gc_data->container),
               (int)(wpt->gc_data->diff / 10), (wpt->gc_data->diff%10)?".5":"",
               (int)(wpt->gc_data->terr / 10), (wpt->gc_data->terr%10)?".5":"");
-    if (wpt->gc_data->desc_short.utfstring) {
+    if (!wpt->gc_data->desc_short.utfstring.isEmpty()) {
       char *stripped_html = strip_html(&wpt->gc_data->desc_short);
       gbfprintf(file_out, "\n%s\n", stripped_html);
       xfree(stripped_html);
     }
-    if (wpt->gc_data->desc_long.utfstring) {
+    if (!wpt->gc_data->desc_long.utfstring.isEmpty()) {
       char *stripped_html = strip_html(&wpt->gc_data->desc_long);
       gbfprintf(file_out, "\n%s\n", stripped_html);
       xfree(stripped_html);
index 54ea46114166b5c71ab8b92809d1702e02c041b6..8088a6c0f6cb2f8fc698c64d29ceef0984e2d6be 100644 (file)
@@ -1246,9 +1246,9 @@ strlower(char *src)
 }
 
 char *
-rot13(const char *s)
+rot13(const QString& s)
 {
-  char *result = xstrdup(s);
+  char *result = xstrdup(s.toUtf8().data());
   char *cur = result;
   int flip = 1;
   while (cur && *cur) {
@@ -1481,13 +1481,13 @@ pretty_deg_format(double lat, double lon, char fmt, const char *sep, int html)
  * <style> </style> - stop overriding styles for everything
  */
 char *
-strip_nastyhtml(const char * in)
+strip_nastyhtml(const QString& in)
 {
   char *returnstr, *sp;
   char *lcstr, *lcp;
 
-  sp = returnstr = xstrdup(in);
-  lcp = lcstr = strlower(xstrdup(in));
+  sp = returnstr = xstrdup(in.toUtf8().data());
+  lcp = lcstr = strlower(xstrdup(in.toUtf8().data()));
 
   while (lcp = strstr(lcstr, "<body>"), NULL != lcp) {
     sp = returnstr + (lcp - lcstr) ; /* becomes <!   > */
@@ -1574,19 +1574,21 @@ strip_nastyhtml(const char * in)
 char *
 strip_html(const utf_string *in)
 {
-  char *outstring, *out;
-  char *instr = in->utfstring;
+  char* outstring, *out;
+  // If toUtf8() is used here, we double encode in the OSM test case.
+  // this may be a bug here or elsewhere.
+  char* instr = xstrdup(in->utfstring.toAscii().data());
   char tag[8];
   unsigned short int taglen = 0;
 
   if (!in->is_html) {
-    return xstrdup(in->utfstring);
+    return instr;
   }
   /*
    * We only shorten, so just dupe the input buf for space.
    */
 
-  outstring = out = xstrdup(in->utfstring);
+  outstring = out = xstrdup(in->utfstring.toUtf8().data());
 
   tag[0] = 0;
   while (*instr) {
index 7a04e5f7dcef24fd69a51cf4e353ff7d0a4bfe6b..2106a97fe1c19382f7a7eb006031b10bcb22746f 100644 (file)
@@ -94,16 +94,9 @@ waypt_dupe(const waypoint *wpt)
     tmp->gc_data->desc_short.is_html = wpt->gc_data->desc_short.is_html;
     tmp->gc_data->desc_long.is_html = wpt->gc_data->desc_long.is_html;
     tmp->gc_data->favorite_points = wpt->gc_data->favorite_points;
+    tmp->gc_data->desc_short.utfstring = wpt->gc_data->desc_short.utfstring;
+    tmp->gc_data->desc_long.utfstring = wpt->gc_data->desc_long.utfstring;
 
-    // memcpy(gc_data, wpt->gc_data, sizeof(*gc_data));
-    if (wpt->gc_data->desc_short.utfstring) {
-      tmp->gc_data->desc_short.utfstring =
-        xstrdup(wpt->gc_data->desc_short.utfstring);
-    }
-    if (wpt->gc_data->desc_long.utfstring) {
-      tmp->gc_data->desc_long.utfstring =
-        xstrdup(wpt->gc_data->desc_long.utfstring);
-    }
     if (wpt->gc_data->placer) {
       tmp->gc_data->placer = xstrdup(wpt->gc_data->placer);
     }
@@ -426,12 +419,6 @@ waypt_free(waypoint *wpt)
   if (wpt->gc_data != &empty_gc_data) {
     geocache_data *gc_data = (geocache_data *)wpt->gc_data;
 
-    if (gc_data->desc_short.utfstring) {
-      xfree(gc_data->desc_short.utfstring);
-    }
-    if (gc_data->desc_long.utfstring) {
-      xfree(gc_data->desc_long.utfstring);
-    }
     if (gc_data->placer) {
       xfree(gc_data->placer);
     }